using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Coriander.Google.Charting
{
    public static class ChartColor
    {
        /// <summary>
        /// Gets a hexadecimal string representing 
        /// <paramref name="color">color</paramref>, including the leading '#'. 
        /// This member always returns hexadecimal color representations.
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static String ToHtml(Color color)
        {
            return ToHtml(color, false);  
        }

        /// <summary>
        /// Gets a hexadecimal string representing 
        /// <paramref name="color">color</paramref>, optionally exlcuding the leading '#'. 
        /// This member always returns hexadecimal color representations.
        /// <seealso cref="System.Drawing.ColorTranslator.ToHtml">
        /// System.Drawing.ColorTranslator.ToHtml</seealso>
        /// </summary>
        /// <remarks>
        /// Q. Why add this?
        /// A. (2008-02-23, framework v2.0.50727) : Currently
        ///     ColorTranslator.ToHtml does not work for named or system colors, like
        ///     Color.AntiqueWhite. It returns the name instead of hex value.
        /// </remarks>
        /// <param name="color"></param>
        /// <param name="excludeHash">Set to false to return a value without leading hash.</param>
        /// <returns></returns>
        public static String ToHtml(Color color, Boolean excludeHash) 
        {
            // [i] No need to validate. Color components cannot be outside hex range.
            
            return String.Format(
                "{0}{1}{2}{3}",
                excludeHash ? String.Empty : "#",
                color.R.ToString("X2"), 
                color.G.ToString("X2"), 
                color.B.ToString("X2")
            ); 

            // return ColorTranslator.ToHtml(color).TrimStart('#');
        }
    }
}
